package demo1;/*

class demo1.Animal {
    public String name;
    public int age;

    public demo1.Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(this.name + "正在吃饭！");
    }
}
class demo1.Dog extends demo1.Animal {
    public demo1.Dog(String name, int age) {
        super(name, age);
    }

    public void bark() {
        System.out.println(this.name + "汪汪叫！");
    }
}

class Cat extends demo1.Animal {
    public Cat(String name, int age) {
        super(name, age);
    }

    public void Mew() {
        System.out.println(this.name + "喵喵叫！");
    }
}

public class demo1.Test {
    public static void main(String[] args) {
        demo1.Dog dog = new demo1.Dog("圆圆",3);
        dog.eat();
        dog.bark();
    }
}
*/

class Animal {
    String name;
    int age;
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat() {
        System.out.println(name + "吃饭");
    }
}
class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }
    /*public void eat() {
        System.out.println(name + "吃骨头~~");
    }*/
}
public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog("小狗", 2);
        animal.eat();
    }
}

// 编译器在编译代码时，并不知道要调用Dog 还是 Cat 中eat的方法
// 等程序运行起来后，形参a引用的具体对象确定后，才知道调用那个方法
// 注意：此处的形参类型必须时父类类型才可以

